package com.cheli.managerAsset.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cheli.commonutils.JwtUtils;
import com.cheli.commonutils.R;
import com.cheli.managerAsset.entity.AsApply;
import com.cheli.managerAsset.service.AsApplyService;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.sql.Wrapper;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cheli
 * @since 2021-05-23
 */
@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/asManager/apply")
public class AsApplyController {
    @Autowired
    private AsApplyService asApplyService;

   @ApiOperation("该员工申请列表")
    @GetMapping("getAssetApplyListPage")
    public R getAssetApplyListPage(HttpServletRequest request){
        log.info("查询申请");
       String id = JwtUtils.getMemberIdByJwtToken(request);
        QueryWrapper<AsApply> queryWrapper = new QueryWrapper<>();

        if(!StringUtils.isEmpty(id)) {
            queryWrapper.eq("staff_id", id);
        }
        List<AsApply> list = asApplyService.list(queryWrapper);
        return R.ok().data("items", list);
    }

    @ApiOperation("该员工申请列表")
    @GetMapping("getAssetApplyListPageAll")
    public R getAssetApplyListPageAll(HttpServletRequest request){
        log.info("管理员查询申请");
        List<AsApply> list = asApplyService.list(null);
        return R.ok().data("items", list);
    }

    @PostMapping("addAssetApply")
    public R addAssetApply(@RequestBody AsApply asset, HttpServletRequest request){
        log.info("新增申请:" + asset);
       String id = JwtUtils.getMemberIdByJwtToken(request);
        asset.setStaffId(id);
        asApplyService.save(asset);
        return R.ok();
    }

}

